<template>
  <el-scrollbar style="height:100%;">
    <div class="container">
      <el-main>
        <div class="cate-article-content" :class="personInfoClass">
          <ul class="cates">
            <li :class="active=='life'?'life-choose':'life'" @click="changeCates('life')">
              生活琐事
              <div :class="active=='life'?'triangle_1':'triangle_none'"></div>
            </li>
            <li :class="active=='study'?'study-choose':'study'" @click="changeCates('study')">
              学习记录
              <div :class="active=='study'?'triangle_2':'triangle_none'"></div>
            </li>
            <li :class="active=='feel'?'feel-choose':'feel'" @click="changeCates('feel')">
              有感而发
              <div :class="active=='feel'?'triangle_3':'triangle_none'"></div>
            </li>
          </ul>
          <div class="bubble" :class="{
            'bubble-bck-life':active=='life',
            'bubble-bck-study':active=='study',
            'bubble-bck-feel':active=='feel'
            }">
            <!-- <vue-waterfall-easy :imgsArr="imgsArr" @scrollReachBottom="getData"></vue-waterfall-easy> -->
            <ul class="cate-article">
              <li v-for="(item,index) in cate_article" :key="index" @click="enterArticle(item._id)">
                <img :src="item.img_cates">
                <p>{{item.title}}</p>
                <div class="article_details">
                  <span><i class="iconfont icon-shijian"></i>{{item.add_time_yd}}</span>
                  <span><i class="iconfont icon-yuedu"></i>{{item.visits}}</span>
                </div>
              </li>
            </ul>
          </div>
        </div>
        <transition name="fade">
          <loading v-if="isLoading"></loading>
        </transition>
      </el-main>
      <el-footer>
        <div class="text1">Copyright © {{year}} by Kpods. All Rights Reserved.</div>
        <div class="text2">备案号......</div>
      </el-footer>
    </div>
  </el-scrollbar>
</template>

<script>
// 引入Vue瀑布流插件
// import vueWaterfallEasy from 'vue-waterfall-easy'
import Loading from './loading/loading.vue'
export default {
  components: { Loading },
  data() {
    return {
      year: new Date().getFullYear(),
      active: 'life',
      cate_article: [],
      // Loading状态
      isLoading: true,
      // 窗口宽度
      windowWidth: document.documentElement.clientWidth
    }
  },
  // components: {
  //   vueWaterfallEasy
  // },
  created() {
    this.changeCates('life')
  },
  computed: {
    // 判断屏幕宽度
    personInfoClass() {
      if (this.windowWidth >= 1080) {
        return 'PC_layout'
      } else if (this.windowWidth < 1080 && this.windowWidth >= 812) {
        return 'middle_layout'
      } else {
        return 'mobile_layout'
      }
    }
  },
  watch: {
    // 监听屏幕宽度
    '$store.state.screenWidth': function(val) { // 监听屏幕宽度变化
      this.windowWidth = val
    }
  },
  methods: {
    getData() {
    },
    // 根据分类获取文章
    changeCates(current) {
      this.active = current
      let cate
      if (current === 'life') {
        cate = '生活琐事'
      } else if (current === 'study') {
        cate = '学习记录'
      } else {
        cate = '有感而发'
      }
      this.isLoading = true
      this.$http.get('article_cates', { params: { cate: cate } }).then(response => {
        this.cate_article = response.data
        this.isLoading = false
      })
    },
    enterArticle(id) {
      this.$router.push(`/Blog/article/${id}`)
      this.$http.put(`article/${id}`).then(response => {
      })
    }
  }
}
</script>

<style lang="less" scoped>
/deep/.el-scrollbar__wrap {
  overflow-x: hidden;
}
/deep/.el-scrollbar__view {
  height: 100%;
}
.container {
  height: 100%;
  .el-main {
    padding: 0;
    min-height: 92%;
    background-image: linear-gradient(
      to right,
      rgba(199, 121, 208, 0.6),
      rgba(75, 192, 200, 0.6)
    );
    .cate-article-content {
      padding: 35px 250px;
      margin-top: 60px;
      .cates {
        margin: 0 auto;
        display: flex;
        justify-content: space-around;
        li {
          display: flex;
          align-items: center;
          justify-content: center;
          box-sizing: border-box;
          font-size: 18px;
          width: 120px;
          height: 50px;
          border-radius: 3px;
          letter-spacing: 1px;
          color: #fff;
          cursor: pointer;
        }
        .life-choose {
          background-color: #8ece6a;
          position: relative;
          .triangle_1 {
            position: absolute;
            width: 0px;
            height: 0px;
            border: 20px solid transparent;
            border-bottom: 20px solid #8ece6a;
            top: 42px;
          }
        }
        .triangle_none {
          display: none;
        }
        .life {
          background-color: #fff;
          border: 4px solid #8ece6a;
          color: #8ece6a;
        }
        .study-choose {
          background-color: #ff9e64;
          position: relative;
          .triangle_2 {
            position: absolute;
            width: 0px;
            height: 0px;
            border: 20px solid transparent;
            border-bottom: 20px solid #ff9e64;
            top: 42px;
          }
        }
        .study {
          background-color: #fff;
          border: 4px solid #ff9e64;
          color: #ff9e64;
        }
        .feel-choose {
          background-color: #6c93eb;
          position: relative;
          .triangle_3 {
            position: absolute;
            width: 0px;
            height: 0px;
            border: 20px solid transparent;
            border-bottom: 20px solid #6c93eb;
            top: 42px;
          }
        }
        .feel {
          background-color: #fff;
          border: 4px solid #6c93eb;
          color: #6c93eb;
        }
      }
      .bubble {
        margin-top: 30px;
        // width: 100%;
        background-color: #fff;
        border-radius: 3px;
        box-shadow: 0 0 15px rgba(68, 68, 68, 0.15);
        overflow-wrap: normal;
        padding: 10px 30px 20px;
        // /deep/.vue-waterfall-easy-scroll {
        //   overflow: visible;
        // }
        .cate-article {
          display: flex;
          justify-content: space-between;
          flex-flow: row wrap;
          li {
            margin-left: 20px;
            margin-top: 20px;
            background-color: #fff;
            padding: 3px;
            cursor: pointer;
            img {
              width: 225px;
            }
            p {
              line-height: 35px;
              width: 200px;
              overflow: hidden;
              white-space: nowrap;
              text-overflow: ellipsis;
              padding: 0 6px;
            }
            .article_details {
              display: flex;
              justify-content: space-between;
              padding: 0 6px;
              color: #666;
              span {
                font-size: 14px;
              }
              i {
                margin-right: 3px;
              }
            }
            &:last-child {
              margin-right: auto;
              margin-bottom: 0px;
            }
          }
        }
      }
      .bubble-bck-life {
        background-color: #8ece6a;
      }
      .bubble-bck-study {
        background-color: #ff9e64;
      }
      .bubble-bck-feel {
        background-color: #6c93eb;
      }
    }
    .middle_layout {
      padding: 35px 100px;
    }
    .mobile_layout {
      padding: 35px 20px;
      .bubble {
        padding: 10px 18px 20px;
        .cate-article {
          li {
            margin-left: 0;
            img {
              width: 157px;
            }
            .article_details {
              padding: 0 6px 0 0;
              margin-right: 1px;
              span {
                font-size: 12px;
              }
              i {
                margin-right: 1px;
              }
            }
            p {
              width: 135px;
            }
          }
        }
      }
    }
  }
  .el-footer {
    // padding: 10px 250px;
    background-color: #24283b;
    color: #fff;
    border-top: 1px solid #cccccc;
    font-size: 14px;
    font-weight: 200;
    text-align: center;
    .text1 {
      padding-top: 10px;
    }
    .text2 {
      padding-bottom: 10px;
    }
  }
}
</style>
